package ref

import (
	"reflect"
	"fmt"
)

func ParseReflect (object interface{}) {
	t := reflect.TypeOf(object)
	val := reflect.ValueOf(object)
	fmt.Printf("type: %v, value:%v\n", t,val)
}

type User struct {
	Name string // 用户姓名
	Age  int // 年龄
}

func (user *User) SayHello() {
	_, err := fmt.Printf("Hello, I am %v\n", user.Name)
	if err != nil {
		panic(fmt.Errorf("SayHello error:%v", err))
	}
}

func (user *User) Say(something string) {
	fmt.Printf("%v\n, isn't it?", something)
}

func (user *User) Discrib() {
	t := reflect.TypeOf(user)
	fmt.Println(t.Name())
	_, err := fmt.Printf("methods count :%v\n", t.NumMethod())
	if err != nil {
		panic(fmt.Errorf("Discrib returns err:%v", err))
	}
	for cnt := 0; cnt < t.NumMethod(); cnt ++ {
		m := t.Method(cnt)
		fmt.Println("func name:", m.Name)
	}
}